<!-- 推广中心 -->
<template>
  <div class="plug-top-ui">
    <!-- 背景图和色块 -->
    <div class="plug-top-bg"></div>
    <!-- 返回按钮 -->
    <img class="plug-back-btn" src="@/assets/defi/back.png" @click="$router.push('/')" alt="back" />
    <!-- 问号按钮 -->
    <img class="plug-help-btn" src="@/assets/defi/wenhao.png" @click="showPopup" alt="help" />
    <!-- 中间大标题 -->
    <div class="plug-top-title-box">
      <div class="plug-top-title">推荐好友</div>
      <div class="plug-top-subtitle">高达 5% 的邀请返利</div>
    </div>
    <!-- 三大区块 -->
    <div class="plug-top-content">
      <div class="plug-top-item">
        <img class="plug-top-icon" src="/static/img/x9L_2914b717_cCe.730b9683.png" alt="推荐好友" />
        <div class="plug-top-label">推荐好友</div>
      </div>
      <div class="plug-top-divider"></div>
      <div class="plug-top-item">
        <img class="plug-top-icon" src="/static/img/fzX_29512232_9kK.6f75d24b.png" alt="朋友收入" />
        <div class="plug-top-label">朋友收入</div>
      </div>
      <div class="plug-top-divider"></div>
      <div class="plug-top-item">
        <img class="plug-top-icon" src="/static/img/xEB_71eca402_ZDf.348ed1f4.png" alt="兑换返利" />
        <div class="plug-top-label">兑换返利</div>
      </div>
    </div>
  </div>
  
  <!-- 推荐连结卡片 -->
  <div class="plug-card">
    <div class="plug-card-title">推荐连结</div>
    <div class="plug-card-row plug-card-row-code">
      <span class="plug-card-label">推广码</span>
      <div class="plug-card-value-wrap">
        <span class="plug-card-value">{{ sharkCode }}</span>
        <Copy :data="sharkCode">
          <template #copyMsg>
            <span></span>
          </template>
        </Copy>
      </div>
    </div>
    <div class="plug-card-row plug-card-row-link">
      <span class="plug-card-label">推广连结</span>
      <div class="plug-card-value-wrap">
        <span class="plug-card-value plug-card-link-text">{{ shareLink }}{{ sharkCode }}</span>
        <Copy :data="`${shareLink}${sharkCode}`">
          <template #copyMsg>
            <span></span>
          </template>
        </Copy>
      </div>
    </div>
    <div class="plug-card-benefit-row">
      <div class="plug-card-benefit">
        <div class="plug-card-benefit-num">5%</div>
        <div class="plug-card-benefit-label">一代收益</div>
      </div>
      <div class="plug-card-benefit">
        <div class="plug-card-benefit-num">3%</div>
        <div class="plug-card-benefit-label">二代收益</div>
      </div>
      <div class="plug-card-benefit">
        <div class="plug-card-benefit-num">1%</div>
        <div class="plug-card-benefit-label">三代收益</div>
      </div>
    </div>
    <div class="plug-card-bottom-row">
      <div class="plug-card-qr">
        <QRCode style="width: 100px; " :address="sharkCode" :size="32" />
      </div>
      <button class="plug-card-btn">海报</button>
    </div>
  </div>

  <!-- 新卡片，底部icon为PNG -->
  <div class="plug-card">
    <div class="plug-card-title">推荐连结</div>
    <div class="plug-card-row plug-card-row-code">
      <span class="plug-card-label">推广码</span>
      <div class="plug-card-value-wrap">
        <span class="plug-card-value">{{ sharkCode }}</span>
        <Copy :data="sharkCode">
          <template #copyMsg>
            <span></span>
          </template>
        </Copy>
      </div>
    </div>
    <div class="plug-card-row plug-card-row-link">
      <span class="plug-card-label">推广连结</span>
      <div class="plug-card-value-wrap">
        <span class="plug-card-value plug-card-link-text">{{ shareLink }}{{ sharkCode }}</span>
        <Copy :data="`${shareLink}${sharkCode}`">
          <template #copyMsg>
            <span></span>
          </template>
        </Copy>
      </div>
    </div>
    <div class="plug-card-benefit-row">
      <div class="plug-card-benefit">
        <div class="plug-card-benefit-num">5%</div>
        <div class="plug-card-benefit-label">一代收益</div>
      </div>
      <div class="plug-card-benefit">
        <div class="plug-card-benefit-num">3%</div>
        <div class="plug-card-benefit-label">二代收益</div>
      </div>
      <div class="plug-card-benefit">
        <div class="plug-card-benefit-num">1%</div>
        <div class="plug-card-benefit-label">三代收益</div>
      </div>
    </div>
    <div class="plug-card-bottom-row">
      <div class="plug-card-qr">
        <img src="/static/img/8WD_87341956_jWM.0a2ad736.png" alt="icon" style="width:32px;height:32px;object-fit:contain;" />
      </div>
    </div>
  </div>
  <img src="/static/img/8WD_87341956_jWM.0a2ad736.png" alt="icon" style="width:100%;height:100%;object-fit:contain;" />


 

  <!-- 质押挖矿规则弹窗 -->
  <Popup
    :show="showRule"
    @handelClose="closePopup"
    :title="txt"
    :content="popupContent"
    :direction="direction"
  >
  </Popup>
</template>

<script setup>
import { NO_SHOW_MEMBER } from '@/config/index'
import { _t18 } from '@/utils/public'
import HeaderBar from '@/components/HeaderBar/index.vue'
import QRCode from '@/components/common/QRCode/index.vue'
import Copy from '@/components/common/Copy/index.vue'
import Tab from '@/components/Tab/index.vue'
import Popup from '@/components/Popup/index.vue'
import { useUserStore } from '@/store/user/index'
import { getAgentInfo, getAgentList } from '@/api/plug.js'
import { onMounted } from 'vue'
import { rulesList } from '@/api/common/index'

const cuttentRight = { iconRight: [{ iconName: 'guize', clickTo: '' }] }
const useStore = useUserStore()
const userInfo = useStore.userInfo
const sharkCode = userInfo?.user?.activeCode
// const shareLink = `${import.meta.env.VITE_APP_PLANFORM_H5}/#/i&`
const shareLink = `${location.origin}/#/i&`
// 推广中心数据
const showLoading = ref(true)
const teamInfo = ref({})
const teamList = ref([])
const popupContent = ref({})
const getTeamInfo = async () => {
  const res = await getAgentInfo()
  if ((res.code = '200')) {
    teamInfo.value = res.data
  }
}
const getTeamList = async () => {
  showLoading.value = true
  const res = await getAgentList({ params: { leve: curIndex.value + 1 } })
  if ((res.code = '200')) {
    setTimeout(() => {
      showLoading.value = false
      teamList.value = res.data
    }, 500)
  }
}
const getPopupContent = async () => {
  const res = await rulesList('PROMOTION_CENTER_EXPLAIN')
  if ((res.code = '200')) {
    popupContent.value = res.data
  }
}
onMounted(() => {
  getTeamInfo()
  getTeamList()
  getPopupContent()
})
// const teamInfo = computed(() => {
//   let obj = {}
//   obj = { one: 10, two: 20, three: 30, sum: '60', amount: 10000000 }
//   return obj
// })
const showRule = ref(false)
const txt = _t18('plug_rule') //规则
const direction = ref('bottom')
let showPopup = () => {
  showRule.value = true
}
let closePopup = () => {
  showRule.value = false
}
const manual = computed(() => {
  let list = []
  list = [
    {
      title: '推广规则',
      content: [
        {
          childContent:
            '如果用户使用了您的邀请码注册，即为您的下级。这个用户再次的邀请用户，即为您的二级下级。 of Stake，即权益证明）机制产生的奖励。在这个机制中，用户将数字资产委托给节点，节点在区块链上行使出块、打包交易等权利并获得奖励。用户根据锁仓数量按比例分享节点获得的奖励。'
        }
      ]
    },
    {
      title: '推广奖励',
      content: [
        {
          childContent:
            '如果用户使用了您的邀请码注册，即为您的下级。这个用户再次的邀请用户，即为您的二级下级。'
        },
        {
          childTitle: '1.下级充值奖励。',
          childContent: '您的下级进行充值，您即可获得他充值金额的1%作为奖励。'
        },
        {
          childTitle: '2.下级挖矿奖励。',
          childContent: '您的下级，如果进行了锁仓挖矿。那么你也可以获得对应的收益。'
        }
      ]
    },
    {
      title: '例：A-B-C-D-E..',
      content: [
        {
          childContent: 'A可以获得B收益的3%'
        },
        {
          childContent: 'A可以获得C收益的2%'
        },
        {
          childContent: 'A可以获得D收益的1%'
        },
        {
          childContent: 'B可以获得C收益的3%'
        },
        {
          childContent: 'B可以获得D收益的2%'
        },
        {
          childContent: 'B可以获得E收益的1%'
        }
      ]
    }
  ]
  return list
})
const curIndex = ref(0)
const tabList = computed(() => {
  let list = []
  // list = ['一代', '二代', '三代']
  list = [_t18('plug_one', ['aams']), _t18('plug_two', ['aams']), _t18('plug_three', ['aams'])]
  return list
})
const changeIndex = (v) => {
  curIndex.value = v
  teamList.value = []
  getTeamList()
}
</script>

<style lang="scss" scoped>
* {
  color: var(--ex-default-font-color);
  font-size: 14px;
}

.content {
  font-size: 0;
  min-height: 100vh;
  position: relative;

  .img-bg {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    object-fit: cover;
  }

  .toBack {
    position: absolute;
    margin-top: 30px;
    margin-left: 20px;

    .back {
      font-size: 18px;
    }
  }

  .code_box {
    min-width: 300px;
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translate(-50%, 0);
    padding: 20px;
    background-color: #fff;
    border-radius: 10px;

    p.code1 {
      font-size: 18px;
      text-align: center;
    }

    p.code2 {
      font-size: 12px;
      text-align: center;
      color: #b5b5b5;
      margin-top: 10px;
    }

    .erweima {
      padding: 20px 0;
      border: 1px solid transparent !important;

      p {
        margin-top: -25px;
        font-size: 20px;
        text-align: center;
        font-weight: bold;
      }
    }

    .link {
      word-break: break-all;
    }
  }
}

.banner {
  .plug_bg {
    background: url('../../../public/resource/images/dark/plugbg.png') no-repeat center;
    background-size: cover;
    padding: 45px 15px 20px;

    .shareContent {
      width: 60%;

      .shareContent_title {
        font-size: 20px;
        color: var(--ex-font-color8);
      }

      .shareContent_info {
        font-size: 14px;
        color: var(--ex-font-color8);
        padding: 10px 0 30px;
      }

      .sharkCode,
      .shareLink {
        p {
          line-height: 1.2;
          font-size: 12px;
          word-break: break-all;
          color: var(--ex-font-color8);
          // word-wrap:break-word;
          // word-break:normal;
        }
      }
    }
  }

  .plugbg {
    background: url('../../../public/resource/images/dark/plugbg.png') no-repeat center;
    background-size: cover;
    padding: 45px 15px 20px;

    .shareContent {
      width: 60%;

      .shareContent_title {
        font-size: 20px;
        color: var(--ex-font-color6);
      }

      .shareContent_info {
        font-size: 14px;

        padding: 10px 0 30px;
      }

      .sharkCode,
      .shareLink {
        p {
          line-height: 1.2;
          font-size: 12px;
          word-break: break-all;
          // word-wrap:break-word;
          // word-break:normal;
        }
      }
    }
  }

  img {
    width: 100%;
    height: auto;
  }

  .teamInfo {
    padding: 15px 0 0;
    display: flex;
    flex-wrap: wrap;

    & > div {
      width: 33.33%;
      padding: 15px 5px;
      text-align: center;
      // flex: 1;
      p {
        height: 30px;
        color: var(--ex-passive-font-color);
        margin-bottom: 15px;
        word-wrap: break-word;
      }

      span {
        font-size: 16px;
        font-weight: 500;
      }
    }
  }
}

.promotion_my {
  .title {
    padding: 25px 15px 20px;
    color: var(--ex-font-color6);
    font-weight: bold;
    font-size: 16px;
  }

  .header {
    padding: 15px 15px 10px;
    display: flex;

    & > p:first-child {
      text-align: left;
    }

    & > p:last-child {
      text-align: right;
    }

    p {
      font-size: 12px;
      flex: 1;
      color: var(--ex-passive-font-color);
      text-align: center;
    }
  }

  .contentBox {
    height: 50vh;
    overflow: auto;
  }

  .content {
    padding: 15px 0;
    display: flex;

    & > p:first-child {
      text-align: left;
    }

    & > p:last-child {
      text-align: right;
    }

    p {
      padding: 0 15px;
      font-size: 12px;
      flex: 1;
      text-align: center;
      font-weight: 400;
    }
  }
}

.van-loading {
  text-align: center;
  padding: 30px;
}

:deep(.van-tab) {
  color: var(--ex-home-list-ftcolor) !important;
}

:deep(.van-tab--active) {
  color: var(--ex-home-list-ftcolor3) !important;
}
.plug-top-ui {
  position: relative;
  height: 240px;
  background: rgba(40,80,231,.93);
  border-radius: 0 0 24px 24px;
  overflow: hidden;
  z-index: 1;
}
.plug-top-bg {
  position: absolute;
  left: 0; top: 0; right: 0; bottom: 0;
  background: url('/static/img/mRK_de8de558_t1e.66c3bf79.png') no-repeat center top;
  background-size: cover;
  opacity: 1;
  z-index: 2;
}
.plug-back-btn {
  position: absolute;
  left: 18px;
  top: 18px;
  width: 28px;
  height: 28px;
  z-index: 3;
  cursor: pointer;
}
.plug-help-btn {
  position: absolute;
  right: 18px;
  top: 18px;
  width: 28px;
  height: 28px;
  z-index: 3;
  cursor: pointer;
}
.plug-top-title-box {
  position: absolute;
  left: 0; right: 0;
  top: 48px;
  text-align: center;
  z-index: 4;
}
.plug-top-title {
  font-size: 22px;
  font-weight: bold;
  color: #fff;
  line-height: 1.2;
}
.plug-top-subtitle {
  font-size: 16px;
  font-weight: bold;
  color: #fff;
  margin-top: 6px;
  line-height: 1.2;
}
.plug-top-content {
  position: absolute;
  left: 0; right: 0;
  bottom: 18px;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  z-index: 4;
  height: 80px;
}
.plug-top-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1 1 0;
  min-width: 0;
}
.plug-top-icon {
  width: 36px;
  height: 36px;
  margin-bottom: 10px;
  filter: brightness(0) invert(1);
}
.plug-top-label {
  color: #fff;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 1px;
}
.plug-top-divider {
  width: 1px;
  height: 36px;
  background: rgba(255,255,255,0.3);
  align-self: center;
}

.plug-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,0.06);
  padding: 24px 20px 18px 20px;
  margin: -40px 16px 24px 16px;
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.plug-card-title {
  text-align: center;
  font-size: 20px;
  font-weight: bold;
  color: #111;
  margin-bottom: 10px;
}
.plug-card-row {
  display: flex;
  align-items: center;
  font-size: 15px;
  margin-bottom: 6px;
  justify-content: space-between;
}
.plug-card-label {
  color: #222;
  min-width: 70px;
  font-weight: 500;
  flex-shrink: 0;
}
.plug-card-value-wrap {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  flex: 1;
  gap: 6px;
}
.plug-card-value {
  color: #111;
  font-weight: 600;
  margin-right: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
  display: inline-block;
}
.plug-card-row-code .plug-card-value {
  max-width: 80px;
}
.plug-card-row-link .plug-card-value {
  max-width: 120px;
}
.plug-card-row Copy {
  margin-left: 2px;
}
.plug-card-benefit-row {
  display: flex;
  justify-content: space-between;
  margin: 18px 0 10px 0;
}
.plug-card-benefit {
  text-align: center;
  flex: 1;
}
.plug-card-benefit-num {
  font-size: 22px;
  font-weight: bold;
  color: #111;
  margin-bottom: 2px;
}
.plug-card-benefit-label {
  font-size: 13px;
  color: #222;
}
.plug-card-bottom-row {
  display: flex;
  align-items: center;
  margin-top: 10px;
  gap: 12px;
}
.plug-card-qr {
  width: 50px; 
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}
.plug-card-btn {
  flex: 1;
  height: 44px;
  background: #111;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 17px;
  font-weight: bold;
  margin-left: 8px;
  cursor: pointer;
}
.erweima {
      border: 1px solid transparent !important;}
</style>
